import syscall
import libc

fn main():void! {
    var pid = syscall.fork() catch err {
        return print('fork err: ', err.msg(), '\n')
    }

    if pid > 0 {
        // 主进程等待 1 秒钟, 等待子进程执行完成
        libc.sleep(1)
        println('start child process complete, will exit')
    } else {
        // child 执行其他东西, 由于此时共用了 fd, 所以直接输出到标准输出中
        println('child process will run')

        syscall.exec('/binerror/echo', ['echo', 'hello world'], ['env1=v', 'env2=2']) catch err {
            print('first exec err: ', err.msg(), '\n')
        }

        syscall.exec('/bin/echo', ['echo', 'hello world'], ['env1=v', 'env2=2'])
    }
}